import {
  getInterviewList,
  createInterview,
  getoneInterview,
  delInterview,
  createInterviewType,
  getInterviewType
} from '../services/repository'
export default {

  namespace: 'repository',

  state: {
    getInterviewType:[],
    getInterview:{
      data:[],
      page:0,
      pageSize:10
    }
  },

  subscriptions: {
    setup({ dispatch, history }) {  // eslint-disable-line
      dispatch({
        type: 'fetchInterview'
      })
    },
  },

  effects: {
    *fetchInterview(actions, { call, put }) {
      const promiseAll = [
        // getInterviewList(),
        getInterviewType(),
        // getoneInterview()
      ]
      const interData = () => Promise.all(promiseAll)
      const res = yield call(interData);
      
      yield put({
        type: 'save',
        payload: {

          getInterviewType: res[0].data,
        }
      })
    },
    *getInterviewList({payload}, {call, put}){
      const res = yield call(getInterviewList, payload)
      console.log(res)
      yield put({
        type: 'save',
        payload: {
          getInterview: {
            data:res.res.data,
            page: 0,
            pageSize: 10
          }
        }
      })
      // yield put(
      //   routerRedux.push({
      //     pathname:"/repository/create"
      //   })
      // )
    },
    *createInterview({payload}, {call, put}){
      console.log(payload)
        const res=yield call(createInterview,payload)
        return Promise.resolve(res)
    },
    *delInterview({payload},{call,put}){
      console.log(payload)
      const res=yield call(delInterview,payload)
      return Promise.resolve(res)
    },
    *fetch({ payload }, { call, put }) {  // eslint-disable-line
      yield put({ type: 'save' });
    },
  },
   
  reducers: {
    save(state, action) {
      return { ...state, ...action.payload };
    },
  },

};
